#include testing
#include cas

(defun test-cas-inc ()
  (define cell (alloc 0))
  (defun inc (loc)
    (let ((old (@ loc)))
      (when (!= (cas loc old (+1 old))
		old)
	(inc loc))))
  (define t1 (thread (inc cell)))
  (define t2 (thread (inc cell)))
  (join t1)
  (join t2)
  (assert-eq cell 2 (@ cell)))

(sandbox test-cas-inc (test-cas-inc))

